<?xml version="1.0" encoding="UTF-8"?>

<!--
    Document   : section_builder.xsl
    Created on : November 3, 2008, 8:25 PM
    Author     : keith
    Description:
        Purpose of transformation follows.
-->
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
            version="1.0"
            xmlns:redirect="http://xml.apache.org/xalan/redirect"
            extension-element-prefixes="redirect">
  <xsl:output method="xml"/>
  
  <xsl:param name="outdir"/>

    <!-- TODO customize transformation rules 
         syntax recommendation http://www.w3.org/TR/xslt 
    -->
  <xsl:template match="/">
    <xsl:apply-templates select="/bouml/usecases" mode="list"/>
    <xsl:apply-templates select="/bouml/usecasediagrams"/>
    <xsl:apply-templates select="/bouml/domainmodels"/>
    <xsl:apply-templates select="/bouml/classdiagrams"/>
    <xsl:apply-templates select="/bouml/usecases"/>
    <xsl:apply-templates select="/bouml/sequencediagrams"/>
    <xsl:apply-templates select="/bouml/communicationdiagrams"/>
    <xsl:apply-templates select="/bouml/classes" mode="list"/>
    <xsl:apply-templates select="/bouml/classes"/>
  </xsl:template>
  
  <!-- generate docbook usecase list -->
  <xsl:template match="usecases" mode="list">
<!--    <xsl:document href="" method="xml"
                  omit-xml-declaration="yes" ident="yes">-->
    <redirect:write file="{$outdir}/usecaselist.xml">
      <chapter id="ch_usecaselist">
        <title>List of Use Cases</title>
        <orderedlist spacing="compact">
          <xsl:for-each select="usecase">
            <xsl:sort select="name"/>
            <listitem>
              <para>
                <xsl:value-of select="name"/>
              </para>
            </listitem>
            <xsl:text>
</xsl:text>
          </xsl:for-each>
        </orderedlist>
      </chapter>
    </redirect:write>
<!--    </xsl:document>-->
  </xsl:template>

  <!-- generate docbook classes list -->
  <xsl:template match="classes" mode="list">
<!--    <xsl:document href="" method="xml"
                  omit-xml-declaration="yes" ident="yes">-->
    <redirect:write file="{$outdir}/classlist.xml">
      <section id="ch_classeslist">
        <title>List of Classes</title>
        <orderedlist spacing="compact">
          <xsl:for-each select="class">
            <xsl:sort select="name"/>
            <listitem>
              <para>
                <xsl:value-of select="name"/>
              </para>
            </listitem>
            <xsl:text>
</xsl:text>
          </xsl:for-each>
        </orderedlist>
      </section>
    </redirect:write>
<!--    </xsl:document>-->
  </xsl:template>

  <!-- generate docbook usecase diagrams -->
  <xsl:template match="usecasediagrams">
    <redirect:write file="{$outdir}/usecasediagrams.xml">
      <chapter id="ch_usecasediagrams">
        <title>Use Case Diagrams</title>
        <xsl:for-each select="usecasediagram">
          <xsl:sort select="name"/>
          <section>
            <xsl:attribute name="id">
              <xsl:value-of select="concat('s_ucd_',position())"/>
            </xsl:attribute>
            <title>
              <xsl:value-of select="name"/>
            </title>
            <figure>
              <xsl:attribute name="id">
                <xsl:value-of select="concat('f',id)"/>
              </xsl:attribute>
              <title>Use Case Diagram:
                <xsl:value-of select="name"/>
              </title>
              <mediaobject>
                <xsl:attribute name="id">
                  <xsl:value-of select="concat('bouml-',image)"/>
                </xsl:attribute>
                <imageobject>
                  <imagedata width="5.5in" scalefit="1"
                              align="center" valign="top">
<!--                  <imagedata width="5.5in" depth="5.5in" 
                              contentwidth="5.5in" contentdepth="5.5in" 
                              scalefit="1" align="center" valign="top">-->
                    <xsl:attribute name="fileref">
                      <xsl:value-of select="concat($outdir,'/bouml/',image)"/>
                    </xsl:attribute>
                  </imagedata>
                </imageobject>
              </mediaobject>
            </figure>
            <para>
              <xsl:value-of select="description"/>
            </para>
          </section>
          <xsl:text>
</xsl:text>
        </xsl:for-each>
      </chapter>
    </redirect:write>
  </xsl:template>
  
  <!-- generate docbook usecase diagrams -->
  <xsl:template match="sequencediagrams">
    <redirect:write file="{$outdir}/sequencediagrams.xml">
      <chapter id="ch_sequencediagrams">
        <title>Sequence Diagrams</title>
        <xsl:for-each select="sequencediagram">
          <xsl:sort select="name"/>
          <section>
            <xsl:attribute name="id">
              <xsl:value-of select="concat('s_sd_',position())"/>
            </xsl:attribute>
            <title>
              <xsl:value-of select="name"/>
            </title>
            <figure>
              <xsl:attribute name="id">
                <xsl:value-of select="concat('f',id)"/>
              </xsl:attribute>
              <title>Sequence Diagram:
                <xsl:value-of select="name"/>
              </title>
              <mediaobject>
                <xsl:attribute name="id">
                  <xsl:value-of select="concat('bouml-',image)"/>
                </xsl:attribute>
                <imageobject>
                  <imagedata width="5.5in" scalefit="1"
                              align="center" valign="top">
<!--                  <imagedata width="5.5in" depth="5.5in" 
                              contentwidth="5.5in" contentdepth="5.5in" 
                              scalefit="1" align="center" valign="top">-->
                    <xsl:attribute name="fileref">
                      <xsl:value-of select="concat($outdir,'/bouml/',image)"/>
                    </xsl:attribute>
                  </imagedata>
                </imageobject>
              </mediaobject>
            </figure>
            <para>
              <xsl:value-of select="description"/>
            </para>
          </section>
          <xsl:text>
</xsl:text>
        </xsl:for-each>
      </chapter>
    </redirect:write>
  </xsl:template>
  
  <!-- generate docbook domain models -->
  <xsl:template match="domainmodels">
    <redirect:write file="{$outdir}/domainmodels.xml">
      <chapter id="ch_domainmodels">
        <title>Domain Models</title>
        <xsl:for-each select="domainmodel">
          <xsl:sort select="name"/>
          <section>
            <xsl:attribute name="id">
              <xsl:value-of select="concat('s_dmd_',position())"/>
            </xsl:attribute>
            <title>
              <xsl:value-of select="name"/>
            </title>
            <figure>
              <xsl:attribute name="id">
                <xsl:value-of select="concat('f',id)"/>
              </xsl:attribute>
              <title>Domain Model:
                <xsl:value-of select="name"/>
              </title>
              <mediaobject>
                <xsl:attribute name="id">
                  <xsl:value-of select="concat('bouml-',image)"/>
                </xsl:attribute>
                <imageobject>
                  <imagedata width="5.5in" scalefit="1"
                              align="center" valign="top">
<!--                  <imagedata width="5.5in" depth="5.5in" 
                              contentwidth="5.5in" contentdepth="5.5in" 
                              scalefit="1" align="center" valign="top">-->
                    <xsl:attribute name="fileref">
                      <xsl:value-of select="concat($outdir,'/bouml/',image)"/>
                    </xsl:attribute>
                  </imagedata>
                </imageobject>
              </mediaobject>
            </figure>
            <para>
              <xsl:value-of select="description"/>
            </para>
          </section>
          <xsl:text>
</xsl:text>
        </xsl:for-each>
      </chapter>
    </redirect:write>
  </xsl:template>

  <!-- generate docbook class diagrams -->
  <xsl:template match="classdiagrams">
    <redirect:write file="{$outdir}/classdiagrams.xml">
      <chapter id="ch_classdiagrams">
        <title>Class Diagrams</title>
        <xsl:for-each select="classdiagram">
          <xsl:sort select="name"/>
          <section>
            <xsl:attribute name="id">
              <xsl:value-of select="concat('s_cd_',position())"/>
            </xsl:attribute>
            <title>
              <xsl:value-of select="name"/>
            </title>
            <figure>
              <xsl:attribute name="id">
                <xsl:value-of select="concat('f',id)"/>
              </xsl:attribute>
              <title>Class Diagram:
                <xsl:value-of select="name"/>
              </title>
              <mediaobject>
                <xsl:attribute name="id">
                  <xsl:value-of select="concat('bouml-',image)"/>
                </xsl:attribute>
                <imageobject>
                  <imagedata width="5.5in" scalefit="1"
                              align="center" valign="top">
<!--                  <imagedata width="5.5in" depth="5.5in"
                              contentwidth="5.5in" contentdepth="5.5in"
                              scalefit="1" align="center" valign="top">-->
                    <xsl:attribute name="fileref">
                      <xsl:value-of select="concat($outdir,'/bouml/',image)"/>
                    </xsl:attribute>
                  </imagedata>
                </imageobject>
              </mediaobject>
            </figure>
            <para>
              <xsl:value-of select="description"/>
            </para>
          </section>
          <xsl:text>
</xsl:text>
        </xsl:for-each>
      </chapter>
    </redirect:write>
  </xsl:template>


  <!-- generate docbook communication diagrams -->
  <xsl:template match="communicationdiagrams">
    <redirect:write file="{$outdir}/communicationdiagrams.xml">
      <chapter id="ch_communicationdiagrams">
        <title>Communication Diagrams</title>
        <xsl:for-each select="communicationdiagram">
          <xsl:sort select="name"/>
          <section>
            <xsl:attribute name="id">
              <xsl:value-of select="concat('s_comm_',position())"/>
            </xsl:attribute>
            <title>
              <xsl:value-of select="name"/>
            </title>
            <figure>
              <xsl:attribute name="id">
                <xsl:value-of select="concat('f',id)"/>
              </xsl:attribute>
              <title>Communication Diagram:
                <xsl:value-of select="name"/>
              </title>
              <mediaobject>
                <xsl:attribute name="id">
                  <xsl:value-of select="concat('bouml-',image)"/>
                </xsl:attribute>
                <imageobject>
                  <imagedata width="5.5in" scalefit="1"
                              align="center" valign="top">
<!--                  <imagedata width="5.5in" depth="5.5in"
                              contentwidth="5.5in" contentdepth="5.5in"
                              scalefit="1" align="center" valign="top">-->
                    <xsl:attribute name="fileref">
                      <xsl:value-of select="concat($outdir,'/bouml/',image)"/>
                    </xsl:attribute>
                  </imagedata>
                </imageobject>
              </mediaobject>
            </figure>
            <para>
              <xsl:value-of select="description"/>
            </para>
          </section>
          <xsl:text>
</xsl:text>
        </xsl:for-each>
      </chapter>
    </redirect:write>
  </xsl:template>

  <xsl:template match="div">
    <xsl:apply-templates/>
  </xsl:template>

  <xsl:template match="style">
    <xsl:apply-templates/>
  </xsl:template>

  <xsl:template match="p">
    <para>
      <xsl:apply-templates/>
    </para>
  </xsl:template>

  <xsl:template match="b">
    <emphasis role="bold">
      <xsl:apply-templates/>
    </emphasis>
  </xsl:template>

  <xsl:template match="i">
    <emphasis role="italics">
      <xsl:apply-templates/>
    </emphasis>
  </xsl:template>

  <xsl:template match="pre">
    <literallayout>
      <xsl:apply-templates/>
    </literallayout>
  </xsl:template>

<!--  <xsl:template match="ul">
    <itemizedlist spacing="compact">
      <xsl:apply-templates/>
    </itemizedlist>
  </xsl:template>

  <xsl:template match="ol">
    <orderedlist spacing="compact">
      <xsl:apply-templates/>
    </orderedlist>
  </xsl:template>
  <xsl:template match="li">
    <listitem>
      <para>
        <xsl:apply-templates/>
      </para>
    </listitem>
  </xsl:template>

  -->

  <xsl:template match="ul">
    <itemizedlist >
      <xsl:for-each select="li">
        <listitem>
          <xsl:apply-templates/>
        </listitem>
      </xsl:for-each>
    </itemizedlist>
  </xsl:template>

  <xsl:template match="ol">
    <informaltable frame="none" rowsep="0" colsep="0">
      <tgroup cols="3">
        <colspec column="1" colname="c1" colwidth="0.25in" />
        <colspec column="2" colname="c2" colwidth="0.5in" />
        <colspec column="3" colname="c3" colwidth="5.0in" />
        <thead>
          <row rowsep="0" colsep="0">
            <entry/>
            <entry namest="c2" nameend="c3">
              <xsl:text>Actor</xsl:text>
            </entry>
          </row>
          <row rowsep="0" colsep="0">
            <entry/>
            <entry/>
            <entry>
              <xsl:text>System</xsl:text>
            </entry>
          </row>
        </thead>
        <tbody>
          <xsl:apply-templates/>
        </tbody>
      </tgroup>
    </informaltable>
  </xsl:template>

  <xsl:template match="li">
    <xsl:variable name="flownum">
      <xsl:choose>
        <xsl:when test="@flownum">
          <xsl:value-of select="concat(@flownum, @altlabel)"/>
        </xsl:when>
        <xsl:otherwise>
          <xsl:value-of select="concat(position(), @altlabel)"/>
        </xsl:otherwise>
      </xsl:choose>
    </xsl:variable>
    <row rowsep="0" colsep="0">
      <entry/>
      <xsl:choose>
        <xsl:when test="@flowcol='A'">
          <entry namest="c2" nameend="c3">
            <xsl:value-of select="$flownum"/>
            <xsl:text>. </xsl:text>
            <xsl:apply-templates/>
          </entry>
        </xsl:when>
        <xsl:otherwise>
          <entry/>
          <entry>
            <xsl:value-of select="$flownum"/>
            <xsl:text>. </xsl:text>
            <xsl:apply-templates/>
          </entry>
        </xsl:otherwise>
      </xsl:choose>
    </row>
  </xsl:template>

  <!-- generate docbook use case text -->
  <xsl:template match="usecase">
<!--    <xsl:text><xsl:value-of select="name"/></xsl:text>
    <xsl:variable name="uc_file" select="concat('../stateofplay/usecase_',id,'.xml')"/>
    <xsl:text>
<xsl:value-of select="$uc_file"/></xsl:text>
    <redirect:write file="{$uc_file}">-->
    <section>
      <xsl:attribute name="id">
        <xsl:value-of select="concat('s_uc_',id)"/>
      </xsl:attribute>
      <title>
        <xsl:value-of select="name"/>
      </title>
      <informaltable >
        <tgroup cols="1">
          <tbody>
<!--                <xsl:if test="description/name">
                  <row>
                    <entry>
                      <emphasis role="bold"><xsl:text>Name:</xsl:text></emphasis>
                      <xsl:text> </xsl:text>
                      <xsl:value-of select="name"/>
                    </entry>
                  </row>
                </xsl:if>
-->
            <xsl:if test="description/scope">
              <row rowsep="0">
                <entry>
                  <emphasis role="bold">
                    <xsl:text>Scope:</xsl:text>
                  </emphasis>
                  <xsl:text> </xsl:text>
                  <xsl:value-of select="description/scope"/>
                </entry>
              </row>
            </xsl:if>
            <xsl:if test="description/level">
              <row rowsep="0">
                <entry>
                  <emphasis role="bold">
                    <xsl:text>Level:</xsl:text>
                  </emphasis>
                  <xsl:text> </xsl:text>
                  <xsl:value-of select="description/level"/>
                </entry>
              </row>
            </xsl:if>
            <xsl:if test="description/pactor">
              <row rowsep="0">
                <entry>
                  <emphasis role="bold">
                    <xsl:text>Primary Actor:</xsl:text>
                  </emphasis>
                  <xsl:text> </xsl:text>
                  <xsl:value-of select="description/pactor"/>
                </entry>
              </row>
            </xsl:if>
            <xsl:if test="description/stakeholder">
              <row rowsep="0">
                <entry>
                  <emphasis role="bold">
                    <xsl:text>Stakeholders and Interests:</xsl:text>
                  </emphasis>
                  <xsl:text> </xsl:text>
                  <xsl:apply-templates select="description/stakeholder"/>
                </entry>
              </row>
            </xsl:if>
            <xsl:if test="description/precond">
              <row rowsep="0">
                <entry>
                  <emphasis role="bold">
                    <xsl:text>Preconditions:</xsl:text>
                  </emphasis>
                  <xsl:text> </xsl:text>
                  <xsl:value-of select="description/precond"/>
                </entry>
              </row>
            </xsl:if>
            <xsl:if test="description/guarantee">
              <row rowsep="0">
                <entry>
                  <emphasis role="bold">
                    <xsl:text>Success Guarantee:</xsl:text>
                  </emphasis>
                  <xsl:text> </xsl:text>
                  <xsl:value-of select="description/guarantee"/>
                </entry>
              </row>
            </xsl:if>
            <xsl:if test="description/main">
              <row rowsep="0">
                <entry>
                  <emphasis role="bold">
                    <xsl:text>Main Success Scenario:</xsl:text>
                  </emphasis>
                  <xsl:text> </xsl:text>
                  <xsl:apply-templates select="description/main"/>
                </entry>
              </row>
            </xsl:if>
            <xsl:if test="description/ext">
              <row rowsep="0">
                <entry>
                  <emphasis role="bold">
                    <xsl:text>Extensions:</xsl:text>
                  </emphasis>
                  <xsl:text> </xsl:text>
                  <xsl:apply-templates select="description/ext"/>
                </entry>
              </row>
            </xsl:if>
            <xsl:if test="description/req">
              <row rowsep="0">
                <entry>
                  <emphasis role="bold">
                    <xsl:text>Requirements:</xsl:text>
                  </emphasis>
                  <xsl:text> </xsl:text>
                  <xsl:apply-templates select="description/req"/>
                </entry>
              </row>
            </xsl:if>
            <xsl:if test="description/tech">
              <row rowsep="0">
                <entry>
                  <emphasis role="bold">
                    <xsl:text>Technology and Data Variations List:</xsl:text>
                  </emphasis>
                  <xsl:text> </xsl:text>
                  <xsl:apply-templates select="description/tech"/>
                </entry>
              </row>
            </xsl:if>
            <xsl:if test="description/freq">
              <row rowsep="0">
                <entry>
                  <emphasis role="bold">
                    <xsl:text>Frequency and Occurrence:</xsl:text>
                  </emphasis>
                  <xsl:text> </xsl:text>
                  <xsl:apply-templates select="description/freq"/>
                </entry>
              </row>
            </xsl:if>
            <xsl:if test="description/misc">
              <row rowsep="0">
                <entry>
                  <emphasis role="bold">
                    <xsl:text>Miscellaneous:</xsl:text>
                  </emphasis>
                  <xsl:text> </xsl:text>
                  <xsl:apply-templates select="description/misc"/>
                </entry>
              </row>
            </xsl:if>
          </tbody>
        </tgroup>
      </informaltable>
    </section>
    <xsl:text>
</xsl:text>
<!--    </redirect:write> -->
  </xsl:template>

  <!-- generate docbook use case text -->
  <xsl:template match="usecases">
    <redirect:write file="{$outdir}/usecases.xml">
      <xsl:for-each select="usecase">
        <xsl:sort select="name"/>
        <xsl:apply-templates  select="."/>
      </xsl:for-each>
    </redirect:write>
  </xsl:template>

  <xsl:template name="class_details">
    <xsl:param name="term"/>

    <informaltable  colsep="0" frame="none" rowsep="0">
      <tgroup cols="1">
        <colspec colname="c1" column="1" colwidth="0.25in"/>
        <colspec colname="c2" column="2" colwidth="5.75in"/>
        <tbody>
          <row>
            <entry namest="c1" nameend="c2">
              <xsl:choose>
                <xsl:when test="static='true'">
                  <emphasis role="underline">
                    <xsl:value-of select="$term"/>
                  </emphasis>
                </xsl:when>
                <xsl:otherwise>
                  <xsl:value-of select="$term"/>
                </xsl:otherwise>
              </xsl:choose>
            </entry>
          </row>
          <xsl:if test="count(description//text())>0">
            <row>
              <entry>
              </entry>
              <entry>
                <xsl:choose>
                  <xsl:when test="description/main">
                    <xsl:apply-templates select="description/main"/>
                  </xsl:when>
                  <xsl:otherwise>
                    <xsl:apply-templates select="description"/>
                  </xsl:otherwise>
                </xsl:choose>
              </entry>
            </row>
          </xsl:if>
        </tbody>
      </tgroup>
    </informaltable>
  </xsl:template>

  <!-- generate docbook use case text -->
  <xsl:template match="class">
    <section>
      <xsl:attribute name="id">
        <xsl:value-of select="concat('s_cls_',id)"/>
      </xsl:attribute>
      <title>
        <xsl:value-of select="name"/>
      </title>

      <!--<xsl:choose>
        <xsl:when test="description/main/pre and count(description/main)=1">
          <para>
            <xsl:value-of select="description/main/pre"/>
          </para>
        </xsl:when>
        <xsl:otherwise>
          <xsl:apply-templates select="description/main"/>
        </xsl:otherwise>
      </xsl:choose>-->
      <xsl:choose>
        <xsl:when test="description/main">
          <xsl:apply-templates select="description/main"/>
        </xsl:when>
        <xsl:otherwise>
          <xsl:apply-templates select="description"/>
        </xsl:otherwise>
      </xsl:choose>

      <xsl:variable name="rows" select="count(children/attribute)+count(children/relation[string(role_name)])+count(children/operation)+count(children/relation[name='&lt;generalisation&gt;'])+count(children/relation[name='&lt;realization&gt;'])"/>

      <informaltable >
        <tgroup cols="1">
          <tbody>
            <xsl:if test="$rows = 0">
              <row rowsep="0">
                <entry>
                  <emphasis role="italics">
                    <xsl:text>There are no attributes, relations, or operations.</xsl:text>
                  </emphasis>
                </entry>
              </row>
            </xsl:if>

            <xsl:if test="children/relation[name='&lt;generalisation&gt;']">
              <row rowsep="0">
                <entry>
                  <emphasis role="strong">Generalization</emphasis>
                </entry>
              </row>
              <row>
                <entry>
                  <itemizedlist spacing="compact">
                    <xsl:for-each select="children/relation[name='&lt;generalisation&gt;']">
                      <listitem>
                        <xsl:text><xsl:value-of select="concat( visibility, type )"/></xsl:text>
                      </listitem>
                  </xsl:for-each>
                  <xsl:text>
</xsl:text>
                </itemizedlist>
              </entry>
            </row>
          </xsl:if>

            <xsl:if test="children/relation[name='&lt;realization&gt;']">
              <row rowsep="0">
                <entry>
                  <emphasis role="strong">Realizations</emphasis>
                </entry>
              </row>
              <row>
                <entry>
                  <itemizedlist spacing="compact">
                    <xsl:for-each select="children/relation[name='&lt;realization&gt;']">
                      <listitem>
                        <xsl:text><xsl:value-of select="concat( visibility, type )"/></xsl:text>
                      </listitem>
                  </xsl:for-each>
                  <xsl:text>
</xsl:text>
                </itemizedlist>
              </entry>
            </row>
          </xsl:if>
            
          <xsl:if test="children/attribute">
            <row rowsep="0">
              <entry>
                <emphasis role="strong">Attributes</emphasis>
              </entry>
            </row>
            <row>
              <entry>
                <xsl:for-each select="children/attribute">
                  <xsl:sort select="name"/>

                  <xsl:variable name="attrTxt">
                    <xsl:choose>
                      <xsl:when test="string(type)">
                        <xsl:value-of select="concat( visibility, name,' :',type)"/>
                      </xsl:when>
                      <xsl:otherwise>
                        <xsl:value-of select="concat( visibility, name )"/>
                      </xsl:otherwise>
                    </xsl:choose>
                  </xsl:variable>
                  <xsl:call-template name="class_details">
                    <xsl:with-param name="term" select="$attrTxt"/>
                  </xsl:call-template>

                  <xsl:text>
</xsl:text>
                </xsl:for-each>
              </entry>
            </row>
          </xsl:if>

          <xsl:if test="children/relation[string(role_name)]">
            <row rowsep="0">
              <entry>
                <emphasis role="strong">Relations</emphasis>
              </entry>
            </row>
            <row>
              <entry>
                <xsl:for-each select="children/relation[string(role_name)]">
                  <xsl:sort select="role_name"/>

                  <xsl:call-template name="class_details">
                    <xsl:with-param name="term">
                      <xsl:value-of select="concat( visibility, role_name )"/>
                    </xsl:with-param>
                  </xsl:call-template>

                  <xsl:text>
</xsl:text>
                </xsl:for-each>
              </entry>
            </row>
          </xsl:if>

          <xsl:if test="children/operation">
            <row rowsep="0">
              <entry>
                <emphasis role="strong">Operations</emphasis>
              </entry>
            </row>
            <row>
              <entry>
                <xsl:for-each select="children/operation">
                  <xsl:sort select="name"/>

                  <xsl:variable name="operSgn">
                    <xsl:choose>
                      <xsl:when test="string(parm_list)">
                        <xsl:value-of select="concat( name,'( ', parm_list, ' )' )"/>
                      </xsl:when>
                      <xsl:otherwise>
                        <xsl:value-of select="concat( name, '()' )"/>
                      </xsl:otherwise>
                    </xsl:choose>
                  </xsl:variable>

                  <xsl:variable name="operTxt">
                    <xsl:choose>
                      <xsl:when test="string(return_type)">
                        <xsl:value-of select="concat( visibility, $operSgn, ': ', return_type)"/>
                      </xsl:when>
                      <xsl:otherwise>
                        <xsl:value-of select="concat( visibility, $operSgn )"/>
                      </xsl:otherwise>
                    </xsl:choose>
                  </xsl:variable>

                  <xsl:call-template name="class_details">
                    <xsl:with-param name="term" select="$operTxt"/>
                  </xsl:call-template>

                  <xsl:text>
</xsl:text>
                </xsl:for-each>
              </entry>
            </row>
          </xsl:if>
        </tbody>
      </tgroup>
    </informaltable>
  </section>
  <xsl:text>
  </xsl:text>
</xsl:template>

  <!-- generate docbook class text -->
<xsl:template match="classes">
  <redirect:write file="{$outdir}/classes.xml">
    <xsl:for-each select="class">
      <xsl:sort select="name"/>
      <xsl:apply-templates  select="."/>
    </xsl:for-each>
  </redirect:write>
</xsl:template>
</xsl:stylesheet>
